/*
 * ===========================================================================================
 * = COPYRIGHT
 *          PAX Computer Technology (Shenzhen) Co., Ltd. PROPRIETARY INFORMATION
 *   This software is supplied under the terms of a license agreement or nondisclosure
 *   agreement with PAX Computer Technology (Shenzhen) Co., Ltd. and may not be copied or
 *   disclosed except in accordance with the terms in that agreement.
 *     Copyright (C) 2023 PAX Computer Technology (Shenzhen) Co., Ltd. All rights reserved.
 * ===========================================================================================
 */

import 'package:flutter/material.dart';
import 'package:pos_link/auto_data_source/auto_data_source_common.dart';
import 'package:pos_link/auto_data_source/auto_form_request_data_source.dart';
import 'package:pos_link/auto_data_source/auto_form_response_data_source.dart';
import 'package:pos_link/auto_pigeon/poslink_sdk_form.dart';
import 'package:pos_link/model/response_db.dart';
import 'comm_setting_view_model.dart';

class FormViewModel extends ChangeNotifier {
  Future startForm(ResponseDataBase responseDataBase, List<Map> dataSource) async {
    POSLinkFormApi FormApi = POSLinkFormApi();

    /// command
    Map cmdData = dataSource.first;
    switch (cmdData[kValue]) {
      case FormCommand.ShowDialogRequest:
        FormShowDialogRequest req = FormReqData.formShowDialogRequest(dataSource);
        FormShowDialogResponse rsp = await FormApi.showDialog(req);
        FormRspData.parseRspFormShowDialogResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ShowTextBoxRequest:
        FormShowTextBoxRequest req = FormReqData.formShowTextBoxRequest(dataSource);
        FormShowTextBoxResponse rsp = await FormApi.showTextBox(req);
        FormRspData.parseRspFormShowTextBoxResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ShowMessageCenterRequest:
        FormShowMessageCenterRequest req = FormReqData.formShowMessageCenterRequest(dataSource);
        FormShowMessageCenterResponse rsp = await FormApi.showMessageCenter(req);
        FormRspData.parseRspFormShowMessageCenterResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ShowItemRequest:
        FormShowItemRequest req = FormReqData.formShowItemRequest(dataSource);
        FormShowItemResponse rsp = await FormApi.showItem(req);
        FormRspData.parseRspFormShowItemResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ClearMessageRequest:
        FormClearMessageRequest req = FormReqData.formClearMessageRequest(dataSource);
        FormClearMessageResponse rsp = await FormApi.clearMessage(req);
        FormRspData.parseRspFormClearMessageResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ShowDialogFormRequest:
        FormShowDialogFormRequest req = FormReqData.formShowDialogFormRequest(dataSource);
        FormShowDialogFormResponse rsp = await FormApi.showDialogForm(req);
        FormRspData.parseRspFormShowDialogFormResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.RemoveCardRequest:
        FormRemoveCardRequest req = FormReqData.formRemoveCardRequest(dataSource);
        FormRemoveCardResponse rsp = await FormApi.removeCard(req);
        FormRspData.parseRspFormRemoveCardResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.InputTextRequest:
        FormInputTextRequest req = FormReqData.formInputTextRequest(dataSource);
        FormInputTextResponse rsp = await FormApi.inputText(req);
        FormRspData.parseRspFormInputTextResponse(rsp, responseDataBase.formData);
        break;
      case FormCommand.ShowMessageRequest:
        FormShowMessageRequest req = FormReqData.formShowMessageRequest(dataSource);
        FormShowMessageResponse rsp = await FormApi.showMessage(req);
        FormRspData.parseRspFormShowMessageResponse(rsp, responseDataBase.formData);
        break;
      default:
        throw Exception('undefined function');
      //break;
    }
  }
}
